import { nodeMode } from "@/hooks/graph/editable/node/node"
import { edgeMode } from "@/hooks/graph/editable/edge/edge"
import { wPublic } from "@/hooks/graph/public/public"
import { wRender } from "@/hooks/graph/render/render"
import { callback } from "@/hooks/graph/editable/callback/callback"

/**
 * g6图形渲染方法
 * @param arg.graphId 图形id
 * @param arg.graphData 图形数据
 * @param arg.graphInstance g6实例
 * @param arg.args 附加参数
 * @param arg.callback 回调函数
 * */
export const wG6Render = (arg) => {
  let { graphInstance } = arg
  // const { callback } = arg
  // 根据arg参数生成全局配置参数（公共测试方法）
  const wPublicConfig = wPublic(arg)
  // 给全局配置参数细化（这个方法是根据原型调整频率高的方法）
  nodeMode(arg, wPublicConfig)
  edgeMode(arg, wPublicConfig)
  // 图形渲染 
  graphInstance = wRender(arg, wPublicConfig)

  console.log('入参', arg)
  console.log('公共配置', wPublicConfig)

  wPublicConfig.eventEmit.forEach((event) => {
    graphInstance?.off(event);
    graphInstance.on(event, (e) => {
      // callback.callback(event, graphInstance, e)
      callback(event, graphInstance, e)
    })
  })

  return graphInstance
}